#include "stm32f10x.h"
#include "usart_dbg_mdwr.h"
#include "stm32f10x_it.h"
#include "gdisp_lld_mdwr.h"
#include "card_app.h"
#include <stdio.h> /* Need for printf function.*/

void LED_Debug_Init(void);
void TIM2_Debug_Init(void);
void USART_Debug_APP_Init(void);


void USART_Debug_APP_Init(void)
{
	/* BaudRate = 115200 baud */
	USART_Debug_MDWR_Init(115200);
}

int main(void)
{
	//SystemInit();
	TIM2_Debug_Init();
	LED_Debug_Init();

	gdisp_lld_init();
	gdisp_lld_clear(0x0000);

	USART_Debug_APP_Init();
	USB_APP_Init();

	while(1)
	{
	}
}

void LED_Debug_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	/* GPIOD Periph clock enable */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

	/* Configure PD0 and PD2 in output pushpull mode */
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

	GPIO_Init(GPIOA, &GPIO_InitStructure);
}

/**
  * Interrupt every 1ms.
  */

void TIM2_Debug_Init(void)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure;

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

	TIM_TimeBase_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBase_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBase_InitStructure.TIM_Period = 2;
	TIM_TimeBase_InitStructure.TIM_Prescaler = 36000 - 1;
	TIM_TimeBaseInit(TIM2, &TIM_TimeBase_InitStructure);

	TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
	NVIC_EnableIRQ(TIM2_IRQn);
	TIM_Cmd(TIM2, ENABLE);
}

#ifdef USE_FULL_ASSERT
/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {}
}
#endif

/************* (C) COPYRIGHT 2009 Wuhan R&D Center, Embest *****END OF FILE****/
